/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package eeep.controles;

import eeep.dao.MateriaDAO;
import eeep.entidades.Materia;
import eeep.excecoes.MJCException;
import eeep.excecoes.MNEException;
import eeep.excecoes.NMIException;

/**
 *
 * @author acdc
 */
public class MateriaControle {
    MateriaDAO dao = new MateriaDAO();
    public void CadastraMateria(Materia materia)throws MJCException{
        try{
            this.BuscarMateriaPorNome(materia.getNome_materia());
            throw new MJCException();
        }catch(MNEException ex){
            dao.salvarMateria(materia);
        }
     
    }
    public Materia BuscarMateriaPorNome(String nome)throws MNEException{
       
        Materia materia =dao.getMateriaPorNome(nome);
    if(materia!=null){
        return materia;
    }   else{
        throw new MNEException();
    }
}public void deletarMateria(String nome)throws MNEException,NMIException{
        this.BuscarMateriaPorNome(nome);
        dao.deleteMateria(nome);
}public void atualizarMateria(Materia materia,String nome)throws MNEException,NMIException{
    try{
    this.BuscarMateriaPorNome(materia.getNome_materia());
    throw new NMIException();
    }
    catch(MNEException ex){
        this.BuscarMateriaPorNome(nome);
        dao.atualizarMateria(materia, nome);
    }
}
}